{{include file="../Common/header"}}
	<!--container-->
	<div id="container">
		<div class="car-logo">
			<a href="index.html"><img src="./Public/home/images/car-logo.png"/></a>
		</div>
		<div class="car-title">
			<h3>我的购物车</h3>
		</div>
		
		<div class="car-goods">
			<div class="car-goods-title">
				<span class="goods-title-0"></span>
				<span class="goods-title-1">商品</span>
				<span class="goods-title-2">单价</span>
				<span class="goods-title-3">数量</span>
				<span class="goods-title-4">小计</span>
				<span class="goods-title-5">操作</span>
			</div>
			{{if value="$goods['goods']"}}
			{{foreach from="$goods['goods']" key="$k" value="$g"}}
			<div class="car-goods-detail goods-box-{{$k}}">
				<div class="goods-detail-0"></div>
				<div class="goods-detail-1">
					<div class="goods-detail-1-img"><img src="{{$g['pic']}}"/></div>
					<div class="goods-detail-1-name">
						<p>{{$g['name']}}</p>
						<span>{{implode(',',$g['options'])}}</span>
					</div>
				</div>
				<div class="goods-detail-2">{{$g['price']}}元</div>
				<div class="goods-detail-3">
					<p>
						<a href="javascript:;" class="del{{$k}}">-</a>
						<input type="text" class="goodsNum{{$k}}" value="{{$g['num']}}"  readonly="readonly"/>
						<input type="hidden"  id="SID{{$k}}" value="{{$k}}" />
						<a href="javascript:;" class="add add{{$k}}">+</a>
					</p>
				</div>
				<div class="goods-detail-4 goods-{{$k}}"><p>{{$g['total']}}元</p></div>
				<div class="goods-detail-5"><a href="javascript:;" class="{{$k}}">删除</a></div>
			</div>
			<script type="text/javascript">
					$(function(){
						//点击减
						$('.goods-detail-3 .del{{$k}}').click(function(){
							var n=$('.goodsNum{{$k}}').attr('value');
							if(n<=1){
								alert('已到最低购买数量，若要删除商品，请点击删除');
								$('.goodsNum{{$k}}').attr('value',1);
							}else{
								n=n*1-1;
								var SID=$('#SID{{$k}}').attr('value');
								$('.goodsNum{{$k}}').attr('value',n);
								$.ajax({
									type:"post",
									url:"{{U('Cart/newNum')}}",
									data:{update:{SID:SID,num:n}},
									dataType:'json',
									success:function(phpData){
										$('.goods-{{$k}} p').html(phpData.total+"元");
										$('.tips .number').html(phpData.total_rows);
										$('.tips strong').html(phpData.all_total);
									}
								});
							}
							
							
						});
						//点击加
						$('.goods-detail-3 .add{{$k}}').click(function(){
							var n=$('.goodsNum{{$k}}').attr('value');
							if(n>=3){
								alert('已到最大购买数量');
								$('.goodsNum{{$k}}').attr('value',3);
							}else{
								n=n*1+1;
								var SID=$('#SID{{$k}}').attr('value');
								$('.goodsNum{{$k}}').attr('value',n);
								$.ajax({
									type:"post",
									url:"{{U('Cart/newNum')}}",
									data:{update:{SID:SID,num:n}},
									dataType:'json',
									success:function(phpData){
										$('.goods-{{$k}} p').html(phpData.total+"元");
										$('.tips .number').html(phpData.total_rows);
										$('.tips strong').html(phpData.all_total);
									}
								});
							}
						});
						//点击删除
						$('.goods-detail-5 .{{$k}}').click(function(){
							var SID=$('#SID{{$k}}').attr('value');
							$.ajax({
									type:"post",
									url:"{{U('Cart/del')}}",
									data:{del:{SID:SID,num:0}},
									dataType:'json',
									success:function(phpData){
										alert('删除成功');
										$('.goods-box-{{$k}}').css({display:'none'});
										$('.tips .number').html(phpData.total_rows);
										$('.tips strong').html(phpData.all_total);
										$('.cart-add span').html(phpData.total_rows);
									}
							});
							
						});
					});
				</script>
			{{endforeach}}
			{{else}}
				<div class="car-goods-detail">
					<p class="car-none">购物车中还没有商品，<a href="{{U('Index/index')}}">去添加商品>></a></p>
				</div>
			{{endif}}
		</div>
		<script type="text/javascript">
		$(function(){
			
			//点击结算，添加订单
			$('.tips .tips-btn').click(function(){
				<?php if($_SESSION['cart']['goods']):?>
				//获取商品总价
				var gototal=$('.tips strong').html();
				//获取商品的总数量
				var goallnum=$('.tips .number').html();
				//发送订单部分数据进行储存
				$.ajax({
					type:"post",
					url:"{{U('Order/addOrder')}}",
					data:{orderData:{gototal:gototal,goallnum:goallnum}},
					dataType:'json',
					success:function(goid){
						$.ajax({
							type:"post",
							url:"{{U('Order/orderList')}}",
							data:{goid:goid},
							success:function(){
								window.location.href="{{U('Order/index')}}";
							}
						});
					}
				});
				<?php else: ?>
				alert('购物车中没有商品，请去添加商品');
				<?php endif ?>
			});	
		})
		</script>
		<div class="car-action">
			<div class="tips">
				<a href="{{U('Index/index')}}">继续购物</a>
				共<span class="number">{{$goods['total_rows']}}</span>件商品
				<p>商品总计：<strong>{{$goods['total']}}</strong><span>元</span></p>
				<a href="javascript:;" class="tips-btn">去结算</a>
			</div>
		</div>
	</div>
	<!--/container-->
	<!--footer-->
	{{include file="../Common/footer"}}
	<!--/footer-->
	</body>
</html>
